package com.qnzw.zjmy.home.ui.widget;

import android.content.Context;
import android.view.View;

import com.lxj.xpopup.core.CenterPopupView;
import com.qnzw.zjmy.R;
import com.qnzw.zjmy.databinding.DialogInviteCodeBinding;

import java.util.Objects;

public class CenterInviteCodeDialog extends CenterPopupView {
    private DialogInviteCodeBinding binding;
    private ConfirmClickListener confirmClickListener;

    public CenterInviteCodeDialog(Context context) {
        super(context);
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_invite_code;
    }

    @Override
    protected void initPopupContent() {
        super.initPopupContent();
        binding = DialogInviteCodeBinding.bind(getPopupImplView());
        binding.tvCancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        binding.tvConfirm.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                String inviteCode = Objects.requireNonNull(binding.etInviteCode.getText()).toString();
                if (inviteCode.isEmpty() || "".equals(inviteCode)) {

                } else {
                    if (confirmClickListener != null) {
                        confirmClickListener.onConfirmClick(inviteCode);
                    }
                    dismiss();
                }
            }
        });
    }

    public void setConfirmClickListener(ConfirmClickListener listener) {
        this.confirmClickListener = listener;
    }

    public interface ConfirmClickListener {
        void onConfirmClick(String inviteCode);
    }
}